home *** CD-ROM | disk | FTP | other *** search
/ Ray Dream Studio 5 / Ray Dream.iso / pc / DreamSDK / Windows / LIB / 3DCOFAIL.CPP next >
Encoding:
C/C++ Source or Header  |  1997-07-11  |  4.3 KB  |  205 lines

  1. /* $Id: 3dcofail.cpp 1.19 1997/07/10 01:21:01 john Exp $ */
  2. /*****************************************************************************\
  3. *                                                                             *
  4. * 3DCoFail.cpp                                                                              *
  5. *           Failure handling for COM extensions                               *
  6. *                                                                             *
  7. *           Copyright (c) 1995, Ray Dream, Inc. All rights reserved.          *
  8. *                                                                             *
  9. \*****************************************************************************/
  10.  
  11. #ifndef __3DCOFAIL__
  12. #include "3DCoFail.h"
  13. #endif
  14.  
  15. #ifndef __I3DSHUTI__
  16. #include "I3DShUti.h"
  17. #endif
  18.  
  19. #ifndef __ISHSMP__
  20. #include "IShSMP.h"
  21. #endif
  22.  
  23. #ifdef __MWERKS__
  24. #define SIZE_T unsigned long
  25. #else
  26. #define SIZE_T unsigned int
  27. #endif
  28.  
  29.  
  30. #include "String.h"
  31. #include <stdlib.h>
  32.  
  33. IShUtilities* gShellUtilities = NULL;
  34. IShActionManager* gActionManager = NULL;
  35. IShMenuManager* gMenuManager = NULL;
  36. IShViewManager* gViewManager = NULL;
  37. IShSMPUtilities* gShellSMPUtilities = NULL;
  38.  
  39. extern "C" {
  40. RDsetjmpProc    RDsetjmp;
  41. }
  42.  
  43. void QuitExtension() {
  44.     gShellUtilities=nil;
  45.     }
  46.  
  47.  
  48. // Initialize gShellUtilities. Must be called to have working failure handling
  49. void InitCoFailure(IShUtilities* shellUtilities)    {
  50.     if (shellUtilities) {
  51.         atexit(QuitExtension);
  52.         gShellUtilities = shellUtilities;
  53.         gShellUtilities->QueryInterface(IID_IShActionManager, (void**)&gActionManager);
  54.         gShellUtilities->QueryInterface(IID_IShMenuManager, (void**)&gMenuManager);
  55.         gShellUtilities->QueryInterface(IID_IShViewManager, (void**)&gViewManager);
  56.         gShellUtilities->QueryInterface(IID_IShSMPUtilities, (void**)&gShellSMPUtilities);
  57.  
  58.         RDsetjmp = (RDsetjmpProc) shellUtilities->GetSetJmpAddress();
  59.         }
  60.     }
  61.  
  62. void FailNIL(void* apointer)    {
  63.     if (!apointer) Failure(-1, 0);
  64.     }
  65.  
  66. void FailOSErr(short err)    {
  67.     if (err) Failure(err, 0);
  68.     }
  69.  
  70. void __cdecl Failure(short error, long message)    {
  71.     if (gShellUtilities)    {
  72.         gShellUtilities->Failure(error, message);
  73.         }
  74.     }
  75.  
  76. FailInfoPtr* __cdecl GetGTopHandler()    {
  77.     if (gShellUtilities)    {
  78.         return (FailInfoPtr*) gShellUtilities->GetGTopHandler();
  79.         }
  80.     else    {
  81.         return NULL;
  82.         }
  83.     }
  84.  
  85. void* RDmalloc(unsigned long  size)    {
  86.     if (gShellUtilities)    {
  87.         return gShellUtilities->Malloc(size);
  88.         }
  89.     else    {
  90.         return NULL;
  91.         }
  92.     }
  93.  
  94. void* RDcalloc(unsigned long nmemb, unsigned long size)    {
  95.     if (gShellUtilities)    {
  96.         return gShellUtilities->Calloc(nmemb, size);
  97.         }
  98.     else    {
  99.         return NULL;
  100.         }
  101.     }
  102.  
  103. void* RDrealloc(void* ptr, unsigned long  size)    {
  104.     if (gShellUtilities)    {
  105.         return gShellUtilities->Realloc(ptr, size);
  106.         }
  107.     else    {
  108.         return NULL;
  109.         }
  110.     }
  111.  
  112. void RDfree(void* ptr)    {
  113.     if (gShellUtilities && ptr)    { //jfs 7/9/97
  114.         gShellUtilities->Free(ptr);
  115.         }
  116.     }
  117.  
  118.  
  119. //    Removed by eg.  This function is also defined in RDMemcpy.cpp
  120.  
  121. #ifdef NEVER
  122. void RDmemmove(void * dstPtr, void const * srcPtr, long size)    {
  123.     memmove(dstPtr, srcPtr, size);
  124.     }
  125. #endif
  126.  
  127.  
  128. long RDRandom() {
  129.     if (gShellUtilities)    {
  130.         return gShellUtilities->Random();
  131.         }
  132.     else    {
  133.         return 0;
  134.         }
  135.     }
  136.  
  137. void RDSetRandomSeed(long seed) {
  138.     if (gShellUtilities)    {
  139.         gShellUtilities->RandomSeed(seed);
  140.         }
  141.     }
  142.  
  143. void* operator new(SIZE_T byteCount) {
  144.     return RDmalloc(byteCount);
  145.     }
  146.  
  147. void  operator delete(void* block) {
  148.     RDfree(block);
  149.     }
  150.  
  151. void* __vec_new(void* p, int nb, int size, void* cst) {
  152.     if (!p) {
  153.         p = RDmalloc(nb*size);
  154.         }
  155.     if (p) {
  156.         int i;
  157.         char* pp = (char*)p;
  158.         for (i = 0; i < nb; i++) {
  159.             (*(void(*)(char*)) cst)(pp);
  160.             pp += size;
  161.             }
  162.         return p;
  163.         }
  164.     return 0;
  165.     }
  166.  
  167. void __vec_delete(void* p, int nb, int size, void* dst, int auto_delete_vec, int auto_delete) {
  168.     if (nb == -1) {
  169.         Failure(-108, 0);
  170.         }
  171.     if (p) {
  172.         int i;
  173.         char* pp;
  174.         pp = ((char*)p) + nb*size;
  175.         for (i = 0; i < nb; i++) {
  176.             pp -= size;
  177.             (*(void(*)(char*, long)) dst)(pp, auto_delete);
  178.             }
  179.         }
  180.     if (p && auto_delete_vec) {
  181.         RDfree(p);
  182.         }
  183.     }
  184.  
  185. #ifdef _WIN
  186. extern "C" {
  187. int  __purecall(void) {
  188.         Failure(-3,0);
  189.         return 0;
  190.     }
  191. int  _purecall(void) {
  192.         Failure(-3,0);
  193.         return 0;
  194.     }
  195. int  purecall(void) {
  196.         Failure(-3,0);
  197.         return 0;
  198.     }
  199. }    
  200. #endif
  201.  
  202.  
  203.  
  204.  
  205.